const fs = require('fs')
const http = require('http')
const path = require('path')
const server = http.createServer()
server.on('request',(req,res)=>{
    const url = req.url
    let fPath = ''
    if (url === '/'){
        fPath = path.join(__dirname,'../node1/clock/index.html')
    }else{
        fPath = path.join(__dirname,'../node1/clock',url)
    }
    fs.readFile(fPath,'utf8',(err,data)=>{
        // res.statusCode = 200
        // res.setHeader('Content-Type', 'text/html;charset=utf-8')
        if (err){
            // res.end('读取文件报错:'+err)
            res.end('404 Not found.')
            return
        }
        res.end(data)
    })
})
server.listen(3000,()=>console.log('server running at http://127.0.0.1:3000'))